// example_driver.c
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/ioport.h>

// probe：设备与驱动匹配成功时调用
static int example_probe(struct platform_device *pdev)
{
    struct resource *res;

    pr_info("example_driver: probe called for device %s\n", dev_name(&pdev->dev));

    // 访问资源
    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    if (res)
        pr_info("example_driver: got MEM resource: start=0x%lx end=0x%lx\n",
                (unsigned long)res->start, (unsigned long)res->end);

    res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
    if (res)
        pr_info("example_driver: got IRQ resource: irq=%lu\n", (unsigned long)res->start);

    return 0;
}

// remove：设备卸载或驱动卸载时调用
static int example_remove(struct platform_device *pdev)
{
    pr_info("example_driver: remove called for device %s\n", dev_name(&pdev->dev));
    return 0;
}

// 平台驱动结构
static struct platform_driver example_driver = {
    .probe  = example_probe,
    .remove = example_remove,
    .driver = {
        .name = "example_dev",
        .owner = THIS_MODULE,
    },
};

module_platform_driver(example_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Platform Driver Example");
